﻿using System.Globalization;
using System.Windows;
using GalaSoft.MvvmLight.Threading;
using System.IO;
using Tomers.WPF.Localization;
using System.Reflection;
using MVVMDialogs;
using DaphneProfiBase;

namespace DaphneProfi
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private static string _sLanguagePath = "AppData/Languages";

        static App()
        {
            DispatcherHelper.Initialize();
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            string sAppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string sLangPath = Path.Combine(sAppPath, _sLanguagePath);

            // register dictionaries
            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("en-US"),
                new XmlLanguageDictionary(Path.Combine(sLangPath, "en-US.xml")));

            LanguageDictionary.RegisterDictionary(
                CultureInfo.GetCultureInfo("cs-CZ"),
                new XmlLanguageDictionary(Path.Combine(sLangPath, "cs-CZ.xml")));

            // set the current language
            LanguageContext.Instance.Culture = CultureInfo.GetCultureInfo("cs-CZ");


            // register dialog service
            ServiceLocator.RegisterSingleton<IDialogService, DialogService>();
            ServiceLocator.RegisterSingleton<IWindowViewModelMappings, WindowViewModelMappings>();

            // init global central configuration class
            Config.InitConfig(sAppPath);

            base.OnStartup(e);
        }
    }
}
